package cn.stylefeng.guns.modular.rw.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.core.ParamUtil;
import cn.stylefeng.guns.modular.rw.entity.BrankBannerOne;
import cn.stylefeng.guns.modular.rw.service.IBrankBannerOneService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 描述：品牌理念区块一表 controller
 * 作者：chenhuiyan
 * 时间：2020-05-06
 */
@Controller
@RequestMapping("/rw/brankBannerOne")
public class BrankBannerOneController extends BaseController {

    private String PREFIX = "/modular/rw/brankBannerOne/";

    @Autowired
    private IBrankBannerOneService brankBannerOneService;

    /**
     * 跳转到管理首页
     */
    @RequestMapping(value = "")
    public String index() {
        return PREFIX + "brankBannerOne.html";
    }

    /**
     * 获取列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list() {
        Map<String, Object> params = ParamUtil.getParams();
        Page<Map<String, Object>> list = brankBannerOneService.list(params);
        return LayuiPageFactory.createPageInfo(list);
    }

    /**
     * 跳转添加/修改页面
     * @param model
     * @param brankBannerOneId
     * @return
     */
    @RequestMapping(value = "/addOrEdit")
    public String addOrEdit(Model model, String brankBannerOneId) {
        model.addAttribute("brankBannerOneId", brankBannerOneId);
        return PREFIX + "brankBannerOne_add.html";
    }

    /**
     * 保存
     * @param brankBannerOne
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save")
    public ResponseData save(BrankBannerOne brankBannerOne) {
        brankBannerOne.setContent(brankBannerOne.getContent().replaceAll("& lt;", "<")
                .replaceAll("& gt;", ">")
                .replaceAll("& #40;", "(")
                .replaceAll("& #40;", ")"));
        if (ToolUtil.isEmpty(brankBannerOne.getId())) {
            brankBannerOne.preInsert();
            brankBannerOneService.save(brankBannerOne);
        }else{
            brankBannerOne.preUpdate();
            brankBannerOneService.updateById(brankBannerOne);
        }
        return SUCCESS_TIP;
    }

    /**
     * 获取详情
     * @param brankBannerOneId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInfoById/{brankBannerOneId}")
    public Object getInfoById(@PathVariable("brankBannerOneId") String brankBannerOneId){
        Map<String, Object> res = brankBannerOneService.getInfoById(brankBannerOneId);
        return res;
    }

}
